package com.strato.batch.base.v1_0_0.common;

import java.util.Collections;
import java.util.List;

import com.strato.batch.base.v1_0_0.api.Job;
import com.strato.batch.base.v1_0_0.api.JobProducer;

public class ListJobProducer<T> implements JobProducer<T> {

	private List<T> list;
	
	public ListJobProducer(List<T> list) {
		super();
		this.list = Collections.synchronizedList(list);
	}

	@Override
	public synchronized Job<T> produce() {
		T obj=list.remove(0);
		JobImpl<T> job=new JobImpl<T>();
		job.setObject(obj);
		return job;
	}

	@Override
	public synchronized boolean available() {
		return !list.isEmpty();
	}

}
